package top.yunmouren.atom.webui.tools;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;

public class socket {
    public static class socketServer{
        ServerSocket socketServer = null;
        public socketClient socketClient = null;
        public socketServer(ServerSocket Socket){
            this.socketServer = Socket;
            try {
                socketClient = new socketClient(socketServer.accept());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public static class socketClient {
        Socket socketClient = null;
        DataInputStream in;
        DataOutputStream out;
        public socketClient(Socket Socket) throws IOException {
            this.socketClient = Socket;
            this.out = new DataOutputStream(Socket.getOutputStream());
            this.in = new DataInputStream(Socket.getInputStream());
            clientSettings();
        }
        public void clientSendsMessage(String msg) throws IOException {
            out.writeUTF(msg);
            out.flush();
        }
        void clientSettings() throws SocketException {
            socketClient.setKeepAlive(true);
            socketClient.setSendBufferSize(4096);
            socketClient.setReceiveBufferSize(2^16);
        }
        public String clientReceivesInformation() throws IOException {
            return in.readUTF();
        }
    }
}
